<template>
	<view class="page">
		<view class="top-view">
			<u-search placeholder="请输入搜索内容" v-model="keyword" height="68rpx" bgColor="#F4F6F8"
				:showAction="false"></u-search>
			<view class="swiper-wrap">
				<u-swiper :height="88" :list="swiperList" @click="clickSwiper" keyName="img"></u-swiper>
			</view>

			<view class="find">
				<view class="find-item" @click="goCard('/pages/client/transmit/transmit')">
					<image class="find-bg" src="../../../static/img/client1.png" mode="aspectFill"></image>
				</view>
				<view class="find-item" @click="goCard('/pages/client/rankUp/rankUp')">
					<image class="find-bg" src="../../../static/img/client2.png" mode="aspectFill"></image>
				</view>
				<view class="find-item" @click="goCard('/pages/card/cardEdit/cardEdit')">
					<image class="find-bg" src="../../../static/img/client3.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="search-wrap flexACB">
				<view class="search-item" @click="provincesShow = true">
					<view class="text">
						{{queryParams.province||'地区'}}
					</view>
					<image class="down" src="../../../static/img/icon-down.png" mode="widthFix"></image>
				</view>
				<view class="search-item" @click="chooseHy">
					<view class="text">
						{{queryParams.type?queryParams.typeName : '行业筛选'}}
					</view>
					<image class="down" src="../../../static/img/icon-down.png" mode="widthFix"></image>
				</view>
				<view class="search-item" @click="chooseHyfl">
					<view class="text">
						{{queryParams.hyflParent?queryParams.hyflParent : '行业分类'}}
					</view>
					<image class="down" src="../../../static/img/icon-down.png" mode="widthFix"></image>
				</view>
				<view class="search-item" @click="toMap">
					<view class="text">
						地图浏览
					</view>
				</view>
			</view>
			<view class="classify-type">
				<u-scroll-list :indicator="false">
					<view class="item" :class="queryParams.hyfl === item.id?'active':''"
						v-for="(item, index) in productTypeList1" :key="index" @click="changeType1(item.id)">
						{{item.typeName}}
					</view>
				</u-scroll-list>
			</view>
		</view>
		<view class="main">
			<view class="user-card" v-for="(item,index) in list" :key="index">
				<view class="top">
					<view class="tips">
						<view class="tip flexAJC" style="background: #FFE6AE;color: #E1A826;">
							{{item.sign||'--'}}
						</view>
						<view class="tip flexAJC" style="background: #FFC3C3;color: #D73030;">
							<!-- 0-经销商；1-厂家；2-产业链 -->
							<text v-if="item.type==0">经销商</text>
							<text v-if="item.type==1">厂家</text>
							<text v-if="item.type==2">产业链</text>
							
						</view>
						<view class="tip flexAJC" style="background: #B2CEFF;color: #326ED5;">
							已认证
						</view>
					</view>
					<view class="user">
						<view class="name-wrap">
							<view class="name">
								{{item.name}}
							</view>
							<view class="label">
								{{item.position}}
							</view>
							<image v-if="item.sfVip" class="vip" src="../../../static/img/vip-icon.png" mode="widthFix"></image>
						</view>
						<view class="ads">
							<image class="icon" src="../../../static/img/gongsi.png" mode="widthFix"></image>
							{{item.qyName}}
						</view>
						<view class="ads">
							<image class="icon" src="../../../static/img/dizhi.png" mode="widthFix"></image>
							{{item.address}}
						</view>
					</view>
					<view class="avatar">
						<image class="tx" :src="fileServer+item.headImg" mode="aspectFill"></image>
						<view class="text">
							已有<text style="font-weight: bold;">{{item.lxNum||0}}</text>人联系
						</view>
					</view>
				</view>
				<view class="content">
					主营品牌产品：{{item.zypphcp}}
				</view>
				<view class="content" v-if="item.type==0">
					销售渠道：{{item.xsqd}}
				</view>
				<view class="btn-list">
					<view class="btn flexAJC" style="background-color: #43B83E;">
						<image class="icon" mode="widthFix" src="../../../static/img/whatsappIcon.png"></image>
						语音
					</view>
					<view class="btn flexAJC" style="background-color: #FA9932;">
						<image class="icon" mode="widthFix" src="../../../static/img/shipin-white.png"></image>
						视频
					</view>
					<view class="btn flexAJC" style="background-color: #4FBFE7;">
						<image class="icon" mode="widthFix" src="../../../static/img/dizhi-white.png"></image>
						导航
					</view>
					<view class="btn flexAJC" style="background-color: #598FEE;">
						<image class="icon" mode="widthFix" src="../../../static/img/Telephone-white.png"></image>
						电话
					</view>
					<view class="btn flexAJC" style="background-color: #16C40B">
						<image class="icon" mode="widthFix" src="../../../static/img/liaoyilia-green.png"></image>
						聊聊
					</view>
				</view>
			</view>
			
			<u-empty v-if="status!='loading'&&list.length==0"
			        mode="data"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
			>
			</u-empty>
			<u-loadmore :status="status" v-else />
		</view>
		<u-picker :show="provincesShow" :columns="provinces" @cancel="provincesShow = false"
			@confirm="chooseProvinces"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				swiperList: [],
				keyword: '',
				queryParams: {
					province: '',
					type: '',
					typeName: '',
					hyflParent: '',
					hyflIndex: '',
					hyflItemIndex: '',
					hyfl: '',
				},
				hyList:[],//行业分类
				list:[],
				status:'loading',//loading / nomore
				pageIndex:1,
				total:0,
				provinces: getApp().globalData.provincesList,//产地
				provincesShow: false,
				productTypeList1:[],

			};
		},
		onLoad() {
			this.getBanner();
			
		},
		onShow() {
			this.getList();
		},
		methods: {
			// 地区
			chooseProvinces(e) {
				console.log(e)
				this.queryParams.province = e.value[0]
				this.provincesShow = false;
				this.pageIndex = 1;
				this.getList()
			},
			getBanner(){
				this.$api.member.getBannerList({type:2}).then(res => {
					if(res.flag){
						let list = res.data;
						list.forEach(ele=>{
							ele.img = this.fileServer +ele.img;
						})
						this.swiperList =list;
					}
				})
			},
			// 行业分类
			chooseHyfl() {
				// console
				if(this.hyList.length==0){
					uni.showToast({
						title: '请先选择行业筛选',
						icon: "none"
					})
					return false
				}
				uni.showActionSheet({
					itemList: this.hyList.map(i => {
						return i.hyflName
					}),
					success: (res) => {
						this.queryParams.hyflItemIndex = ''
						this.queryParams.hyflParent = this.hyList[res.tapIndex].hyflName
						this.queryParams.hyflIndex = res.tapIndex
						this.getProductTypeList(this.hyList[res.tapIndex].data[0].id)
					}
				})
			
			},
			// 行业筛选
			chooseHy() {
				uni.showActionSheet({
					itemList: getApp().globalData.typeList.map(i => {
						return i.label
					}),
					success: (res) => {
						this.queryParams.type = getApp().globalData.typeList[res.tapIndex].value
						this.queryParams.typeName = getApp().globalData.typeList[res.tapIndex].label
						this.queryParams.hyflItemIndex = '';
						this.queryParams.hyflParent = '';
						this.queryParams.hyflIndex = '';
						this.productTypeList1 = [];
						this.getHylbList();
						this.pageIndex = 1
						this.getList()
						// this.$forceUpdate()
					}
				})
			},
			changeType1(type) {
				
				this.queryParams.hyfl = type;
				this.pageIndex = 1
				this.getList()
			},
			getList(){
				// hyfl 行业分类
				// memberId 
				// pageIndex 
				// province  省份
				// type	分类：0--经销商；1--厂家；2--产业链
				// hyflParent: '',
					// hyflIndex: '',
					// hyflItemIndex: '',
					// hyfl: '',
				this.status = 'loading';
				let pageIndex = this.pageIndex;
				let queryParams = {...this.queryParams,pageIndex}
				this.$api.mp.getMpZkhList(queryParams).then(res => {
					uni.stopPullDownRefresh(); // 关闭下拉刷新 
					if(res.code==200){
						let list = res.rows;
						if(pageIndex==1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						this.total = res.total;
						if(this.list.length<res.total){
							this.status = 'loadmore';
						}else{
							this.status = 'nomore';
						}
					}
				})
			},
			getHylbList() {
				this.$api.company.getHylbList({
					type: this.queryParams.type
				}).then(res => {
					this.hyList = res.data
				})
			},
			getProductTypeList(id) {
				this.$api.company.getProductTypeList({
					productTypeId: id
				}).then(res => {
					this.productTypeList1 = res.data
				})
			},
			clickSwiper() {},
			// 找客户转发、去名片
			goCard(url){
				uni.navigateTo({
					url: url
				})
			},
			toMap() {
				uni.navigateTo({
					url: "/pages/client/mapMemo/mapMemo?type=zkh"
				})
			},
		},
		//上拉加载
		onReachBottom() {
			if(this.status == 'nomore'){
				return false
			}
			this.pageIndex++;
			this.getList();
		},
		onPullDownRefresh () {
		  this.pageIndex = 1;
		  this.getList();
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #F5F5F5;min-height: 100vh;

		.top-view {
			width: 100%;
			background-color: #fff;
			padding: 20rpx 32rpx 0;

			.swiper-wrap {
				margin-top: 12rpx;
			}

			.find {
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;

				.find-item {
					position: relative;
					width: 220rpx;
					height: 138rpx;

					.find-bg {
						position: absolute;
						width: 100%;
						height: 100%;
						left: 0;
						top: 0;
						z-index: 1;
					}
				}
			}

			.search-wrap {
				width: 100%;
				padding: 28rpx 0 24rpx;

				.search-item {
					height: 44rpx;
					display: flex;
					align-items: center;

					.text {
						line-height: 44rpx;
						max-width: 150rpx;
						color: #333;
						font-size: 32rpx;margin-right: 5rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
					}

					.down {
						width: 22rpx;
						height: auto;
					}
				}
			}
			.classify-type {
				.item {
					width: auto;
					height: 56rpx;
					background: #EBEBEB;
					border-radius: 28rpx;
					padding: 0 12rpx;
					display: inline-block;
					margin-right: 20rpx;
					font-size: 28rpx;
					white-space: nowrap;
					line-height: 56rpx;
			
					&.active {
						background: #EC2424;
						color: #fff;
					}
				}
			}
		}

		.main {
			position: relative;
			padding: 20rpx;
			overflow: hidden;

			.user-card {
				width: 100%;
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 24rpx;
				margin-bottom: 24rpx;

				.top {
					width: 100%;
					display: flex;
					padding-bottom: 16rpx;
					margin-bottom: 18rpx;
					border-bottom: 1px solid #F0F0F0;

					.tips {
						width: 118rpx;
						border-radius: 6rpx;
						overflow: hidden;
						flex-shrink: 0;

						.tip {
							width: 100%;
							height: 40rpx;
						}
					}

					.user {
						flex: 1;
						padding: 0 0 0 12rpx;

						.name-wrap {
							line-height: 44rpx;

							.name {

								font-size: 32rpx;
								font-weight: bold;
								margin-right: 10rpx;
								display: inline-block;
							}

							.label {
								font-size: 24rpx;
								color: #AAAAAA;
								display: inline-block;
								margin-right: 6rpx;
							}

							.vip {
								display: inline-block;
								width: 34rpx;
								height: auto;
							}

							.dept {
								width: auto;
								display: inline-block;
								height: 36rpx;
								border-radius: 18rpx;
								border: 1px solid #DE3333;
								color: #DE3333;
								font-size: 24rpx;
								padding: 0 20rpx;
								line-height: 34rpx;
							}
						}

						.ads {
							color: #777777;
							font-size: 28rpx;
							line-height: 40rpx;

							.icon {
								display: inline-block;
								width: 24rpx;
								height: auto;
								margin-right: 6rpx;
							}
						}
					}

					.avatar {
						flex-shrink: 0;
						display: flex;
						flex-direction: column;
						align-items: flex-end;

						.tx {
							width: 48rpx;
							height: 48rpx;
							border-radius: 50%;
						}

						.text {
							margin-top: 40rpx;
							font-size: 24rpx;
						}
					}

					.avatar-left {
						width: 88rpx;
						height: 88rpx;
						position: relative;

						.tx {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}

						.vip {
							position: absolute;
							right: 0;
							top: 0;
							width: 28rpx;
							height: auto;
						}
					}

					.talk-btn {
						width: 120rpx;
						height: 50rpx;
						background: #16C40B;
						border-radius: 25rpx;
						color: #FFFFFF;
						font-size: 24rpx;
						align-self: center;

						.icon {
							width: 24rpx;
							height: auto;
							margin-right: 4rpx;
						}
					}

				}

				.content {
					color: #AAAAAA;
					line-height: 40rpx;
					font-size: 28rpx;
					margin-bottom: 10rpx;
				}

				.btn-list {
					margin-top: 10rpx;
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.btn {
						width: 120rpx;
						height: 50rpx;
						font-size: 24rpx;
						color: #FFFFFF;
						border-radius: 25rpx;

						.icon {
							width: 24rpx;
							height: auto;
							margin-right: 4rpx;
						}
					}
				}

				.content-text {
					padding: 20rpx 0 0 0;
					font-size: 28rpx;
					border-top: 1px solid #F0F0F0;
				}
			}
		}
	}
</style>